#!/bin/sh
project_home="/Users/Siyalrach/Workspace/P2PNProject/"
port=50000
superNode=""
#ip="10.185.18.166"
ip="127.0.0.1"
maxVisible=5
max=20 #Max number of peers
i=1

cd ${project_home}/bin

RANDOM=$$$(date +%s)

while [ $i -le $max ] #Number of peers to create
do
  porti=$(($port+$i))
  id=P$i
  folder=$project_home/folder/$((($RANDOM%10)+1))
  nrNeighbors=$((($RANDOM%10)+1))
  capacity=$(($RANDOM%3)) #computatinal/bandwith capacity of a node
  
  #create super node
  if [ $i -eq 1 ]
  then
	superNode=$ip":"$porti
  fi
  
  #create super node
  if [ $i -le $maxVisible ]
  then
	xterm -e "java main.Peer $porti $id $nrNeighbors $superNode $capacity $folder" &
  else
   	java main.Peer $porti $id $nrNeighbors $superNode $capacity $folder&
  fi
  
  i=$(($i+1))

  sleep "1"
done
